﻿using System;

using ApplicationLibrary;
using ApplicationLibrary.SqlConnector;

namespace Fighter.Fights.ModuleData
{
    internal class RegisterModule : ApplicationLibrary.SqlConnector.RegisterModule
    {
        public override string Application()
        {
            return "FGHT";
        }

        public override string Module()
        {
            return "FIGH";
        }

        public override int CurrentVersion()
        {
            return 1;
        }

        public override Version DllVersion
        {
            get
            {
                return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            }
        }

        public override void RegisterCountersAndCodes()
        {
            GlobalInfo.AddCounter(Counters.Match.Int(), Properties.Resources.CN_Match);
        }

        public override void AddScrounger(ApplicationLibrary.DBManager.iScrounger frm, NameSpace nameSpace)
        {
            //if (nameSpace.ApplicationPath == "Fighter.Fighter.Masters.Forms.Masters")
            //    frm.ScroungerList.Add()
        }

        public override ApplicationLibrary.Preferences.PreferencePanel[] RegisterPreferences()
        {
            //return new ApplicationLibrary.Preferences.PreferencePanel[]
            //{
            //    new AccountingPreferencePanel()
            //};
            return null;
        }

        protected override bool CreateDBTables()
        {
            SqlCreateTable newTable = new SqlCreateTable(SqlABConnection);

            #region FG_Fight
            if (SearchTable(FG_Fight.Name))
            {
                newTable.NewTable(FG_Fight.Name);

                newTable.AddColumn(FG_Fight.ID);
                newTable.AddColumn(FG_Fight.Description);
                newTable.AddColumn(FG_Fight.Active);

                newTable.AddPrimaryKey(new iColumn[] { FG_Fight.ID });

                newTable.Create();
            }
            #endregion

            #region FG_Registration
            if (SearchTable(FG_Registration.Name))
            {
                newTable.NewTable(FG_Registration.Name);

                newTable.AddColumn(FG_Registration.Mail);
                newTable.AddColumn(FG_Registration.Athlete);
                newTable.AddColumn(FG_Registration.Fight);

                newTable.AddColumn(FG_Registration.ChausLight);
                newTable.AddColumn(FG_Registration.SavateAss);
                newTable.AddColumn(FG_Registration.PointFight);
                newTable.AddColumn(FG_Registration.LightContact);
                newTable.AddColumn(FG_Registration.KickLight);
                newTable.AddColumn(FG_Registration.K1Light);
                newTable.AddColumn(FG_Registration.ThaiLight);
                newTable.AddColumn(FG_Registration.MmaLight);
                newTable.AddColumn(FG_Registration.Grapling);

                newTable.AddColumn(FG_Registration.ChaussCombact);
                newTable.AddColumn(FG_Registration.SavateCombact);
                newTable.AddColumn(FG_Registration.FullContact);
                newTable.AddColumn(FG_Registration.LowKick);
                newTable.AddColumn(FG_Registration.K1Rules);
                newTable.AddColumn(FG_Registration.ThaiFull);
                newTable.AddColumn(FG_Registration.MMAFull);
                newTable.AddColumn(FG_Registration.Checked);

                newTable.AddPrimaryKey(FG_Registration.Mail, FG_Registration.Athlete, FG_Registration.Fight);

                newTable.Create();
            }
            #endregion

            return true;
        }

        protected override bool UpdateDBTables()
        {
            //if (dbVersion < 2)
            //{
            //    SqlCreateTable alterMaster = new SqlCreateTable(SqlABConnection);

            //    if (!SearchColumn(FG_Masters.Email))
            //    {
            //        alterMaster.AlterTable(FG_Masters.Name);
            //        alterMaster.AddColumn(FG_Masters.Email);
            //        alterMaster.Alter();
            //    }
            //}

            return true;
        }
    }
}